package org.ilovecode.mvc
{
	import flash.display.Sprite;
	import flash.errors.IllegalOperationError;
	import flash.events.EventDispatcher;
	
	import org.ilovecode.events.GUIEvent;
	import org.ilovecode.screen.Screen;
	
	public class Model extends EventDispatcher implements IModel
	{
		private static var _instance:IModel;
		
		protected var _currentScreen:Screen;
		protected var _screenXMLs:Array;
		
		public function Model(lock:Singleton)
		{
			if (!lock) throw new IllegalOperationError("Can't instantiate Singleton class, call getInstance method");
		}
		
		public static function getInstance():IModel
		{
			if (!_instance) _instance = new Model(new Singleton());
			
			return _instance;
		}
		
		public function get currentScreen():Screen
		{
			return _currentScreen;
		}
		
		public function set currentScreen(value:Screen):void
		{
			_currentScreen = value;
			this.dispatchEvent(new GUIEvent(GUIEvent.SWITCH_SCREEN));
		}
		
		public function get screenXMLs():Array
		{
			return _screenXMLs;
		}
		
		public function set screenXMLs(value:Array):void
		{
			_screenXMLs = value;
		}
		
		
	}
}

//Private class for Singleon pattern
class Singleton { public function Singleton() {} }